<template>
  <BasicModal
    @register="register"
    title="请给出自评评分和完成情况"
    :helpMessage="[
      '标准评定任务完成等级说明：',
      'A.已完成：全部完成任务内容；',
      'B.基本完成：完成任务内容的80%以上；',
      'C.正在进行；',
      'D.未开展;',
      '标准评定任务完成等级，目标考核管理系统将按照“目标完成率=已完成的任务数量÷目标任务总数”进行核算（其中任务数量均按照《指标体系》的二级指标进行计数）',
    ]"
    :okButtonProps="{ disabled: false }"
    @ok="upTimeLast"
  >
    <div style="margin-bottom: 25px; margin-left: 30px">
      自评等级
      <RadioGroup v-model:value="value1" style="margin-left: 10px" button-style="solid">
        <RadioButton value="A">A</RadioButton>
        <RadioButton value="B">B</RadioButton>
        <RadioButton value="C">C</RadioButton>
        <RadioButton value="D">D</RadioButton>
      </RadioGroup>
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px; margin-top: 10px">
      自我评分
      <!-- -{{ showTrue }}--{{ upLoadShow }} -->
      <a-input
        v-model:value="zipingfenshu"
        style="width: 200px; margin-left: 5px"
        @input="handleInput"
      />
    </div>
    <div style="margin-bottom: 25px; margin-left: 30px">
      完成情况
      <!-- v-show="markResultVOList.length !== 0" -->
      <a-textarea
        v-model:value="zipingfenshuneirong"
        style="width: 380px; margin-left: 5px"
        :auto-size="{ minRows: 2, maxRows: 6 }"
      />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Radio } from 'ant-design-vue';
  import { taskInterimMark, taskInterimMarkPUT } from '/@/api/basic/qimo/index';
  import { useMessage } from '/@/hooks/web/useMessage';
  const emit = defineEmits(['success', 'register']);
  const RadioGroup = Radio.Group;
  const RadioButton = Radio.Button;
  const { createMessage } = useMessage();
  let zipingfenshuneirong: any = ref();
  let zipingfenshu: any = ref();
  let record: any = ref();
  const value1 = ref<string>('A');

  const [register, { closeModal }] = useModalInner((data) => {
    // 赋值
    record.value = { ...data?.detailResule };
    // console.log(record.value, '555');
    if (record.value.taskTargetMark) {
      if (
        record.value.taskTargetMark.selfScore &&
        record.value.taskTargetMark.selfRemark &&
        record.value.taskTargetMark.selfLevel
      ) {
        zipingfenshu.value = record.value.taskTargetMark.selfScore;
        zipingfenshuneirong.value = record.value.taskTargetMark.selfRemark;
        value1.value = record.value.taskTargetMark.selfLevel;
      } else {
        zipingfenshuneirong.value = '';
        zipingfenshu.value = '';
        value1.value = 'A';
      }
    } else {
      zipingfenshuneirong.value = '';
      zipingfenshu.value = '';
      value1.value = 'A';
    }
  });
  const handleInput = (value: string) => {
    const numValue = value.replace(/\D/g, '');
    if (numValue.length > 2) {
      zipingfenshu.value = numValue.slice(0, 2);
    } else {
      zipingfenshu.value = numValue;
    }
  };
  async function upTimeLast() {
    if (zipingfenshu.value !== undefined && zipingfenshuneirong.value !== undefined) {
      console.log(zipingfenshu.value, record.value.twoLevelScore, '555555');
      if (zipingfenshu.value > record.value.twoLevelScore) {
        createMessage.error(`自评分数不能大于项目分值，请重新填写`);
      } else {
        if (record.value.taskTargetMark) {
          // if (
          //   record.value.taskTargetMark.selfScore &&
          //   record.value.taskTargetMark.selfRemark &&
          //   record.value.taskTargetMark.selfLevel
          // ) {
          const arrchage = {
            id: record.value.taskTargetMark.id,
            twoLevelId: record.value.id,
            selfScore: zipingfenshu.value,
            selfLevel: value1.value,
            selfRemark: zipingfenshuneirong.value,
            tenantId: record.value.tenantId,
          };
          await taskInterimMarkPUT(arrchage);
          zipingfenshuneirong.value = '';
          zipingfenshu.value = '';
          value1.value = 'A';
          emit('success');
          // } else {
          //   const arr = {
          //     twoLevelId: record.value.id,
          //     selfScore: zipingfenshu.value,
          //     selfLevel: value1.value,
          //     selfRemark: zipingfenshuneirong.value,
          //     tenantId: record.value.tenantId,
          //   };
          //   await taskInterimMark(arr);
          //   zipingfenshuneirong.value = '';
          //   zipingfenshu.value = '';
          //   value1.value = '10';
          //   emit('success');
          // }
        } else {
          const arr = {
            twoLevelId: record.value.id,
            selfScore: zipingfenshu.value,
            selfLevel: value1.value,
            selfRemark: zipingfenshuneirong.value,
            tenantId: record.value.tenantId,
          };
          await taskInterimMark(arr);
          zipingfenshuneirong.value = '';
          zipingfenshu.value = '';
          value1.value = 'A';
          emit('success');
        }
        closeModal();
        zipingfenshuneirong.value = '';
        zipingfenshu.value = '';
        value1.value = 'A';
      }
    } else {
      createMessage.error(`评分或评分依据不能为空`);
    }
  }
</script>
